package com.changgou.consumer.service.impl;

import com.changgou.consumer.dao.SeckillGoodsMapper;
import com.changgou.consumer.dao.SeckillOrderMapper;
import com.changgou.consumer.service.SecKillOrderService;
import com.changgou.seckill.pojo.SeckillOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SeckillOrderServiceImpl implements SecKillOrderService {

    @Autowired
    private SeckillOrderMapper seckillOrderMapper;

    @Autowired
    private SeckillGoodsMapper seckillGoodsMapper;

    //添加订单
    @Override
    @Transactional
    public int createOrder(SeckillOrder seckillOrder) {
        int count = seckillGoodsMapper.updateStockCount(seckillOrder.getId());
        if (count<=0){
            return count;
        }
        count = seckillOrderMapper.insertSelective(seckillOrder);
        if (count<=0){
            return count;
        }
        return 1;
    }
}
